var http = require('http'),
    qs   = require('querystring'),
    data = {}
module.exports = function(){
  http.get('/', function(req, res) {
    var code = req.query.code
    data={
      js_code: code,
      appid: 'wxbc245c36b850dfe0',
      secret: 'c40f71381b878fce313e51cb3e63b78d',
      grant_type: 'authorization_code'
    }
  });

  var conentData = qs.stringify(data);

  var options = {  
    hostname: 'https://api.weixin.qq.com',  
    port: 80,  
    path: '/sns/jscode2session?' + conentData,  
    method: 'GET'  
  };  
  var req = http.request(options, function (res) {  
    console.log('STATUS: ' + res.statusCode);  
    console.log('HEADERS: ' + JSON.stringify(res.headers));  
    res.setEncoding('utf8');  
    res.on('data', function (chunk) {  
        console.log('BODY: ' + chunk);  
    });  
  });  
    
  req.on('error', function (e) {  
    console.log('problem with request: ' + e.message);  
  });  
    
  req.end();  
}
